package com.lemon.smartsafetynew.ui.activity.record;

import android.os.Bundle;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.AppManager;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.ui.activity.base.SwipeBackActivity;
import com.lemon.smartsafety.utils.app.UIHelper;
import com.lemon.smartsafetynew.entity.ledger.LedgerBuildingCheckItemVo;
import com.lemon.smartsafetynew.entity.ledger.LedgerBuildingItemVo;
import com.lemon.smartsafetynew.entity.me.MeCompanyVo;
import com.lemon.smartsafetynew.ui.activity.ledger.LedgerBuildingCheckItemDetailActivity;
import com.lemon.smartsafetynew.ui.fragment.ledger.LedgerBuildingCheckItemListFragment;
import com.lemon.smartsafetynew.util.constants.KeyConstants;

/**
 * 检查点位功能页
 * Created by Andrew on 2018/1/23.
 */

public class RecordPatrolActivity extends SwipeBackActivity
        implements RecyclerTClickListener<LedgerBuildingCheckItemVo> {

    private static MeCompanyVo companyVo;
    private static LedgerBuildingItemVo ledgerBuildingItemVo;

    @Override
    protected void getBundleArgs() {
        super.getBundleArgs();

        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            if (bundle.containsKey(KeyConstants.KEY_COMPANY_VO)) {
                companyVo = (MeCompanyVo) bundle.getSerializable(KeyConstants.KEY_COMPANY_VO);
            }
        }
    }


    @Override
    protected void initTitle() {
        this.setBarTitle("检查点位");
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_record_patrol;
    }

    @Override
    protected void initViews() {
        super.initViews();

        initFragment();
    }

    private void initFragment() {
        ledgerBuildingItemVo = new LedgerBuildingItemVo();
        ledgerBuildingItemVo.setBuilding_id(companyVo.getCompany_id());
        LedgerBuildingCheckItemListFragment ledgerBuildingCheckItemListFragment;
        ledgerBuildingCheckItemListFragment = LedgerBuildingCheckItemListFragment.newInstance(ledgerBuildingItemVo);
        ledgerBuildingCheckItemListFragment.setListener(RecordPatrolActivity.this);
        getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout, ledgerBuildingCheckItemListFragment).commit();
    }

    @Override
    protected void callFinish() {
        AppManager.getAppManager().finishActivity(RecordPatrolActivity.this);
    }

    @Override
    public void onItemClick(LedgerBuildingCheckItemVo data, int position) {

        Bundle bundle = new Bundle();
        bundle.putSerializable(KeyConstants.KEY_LEDGER_PATROL_CHECK_ITEM_VO, data);
        bundle.putSerializable(KeyConstants.KEY_LEDGER_PATROL_BUILDING_VO, ledgerBuildingItemVo);
        UIHelper.showActivity(RecordPatrolActivity.this, bundle, LedgerBuildingCheckItemDetailActivity.class);

    }
}
